package com.zwps.common.controller.swagger;

import java.lang.annotation.Annotation;

import io.swagger.v3.oas.annotations.ExternalDocumentation;
import io.swagger.v3.oas.annotations.extensions.Extension;
import io.swagger.v3.oas.annotations.headers.Header;
import io.swagger.v3.oas.annotations.links.Link;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.DiscriminatorMapping;
import io.swagger.v3.oas.annotations.media.Encoding;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.SchemaProperty;
import io.swagger.v3.oas.annotations.responses.ApiResponse;

/**
 * 用于动态创建文档注解
 * 
 * @ClassName: SwaggerBuilder
 * @Description:
 * @author lyh
 * @date 2023年7月30日 下午9:55:34
 *
 */
public class SwaggerBuilder {

    public static ApiResponse createApiResponse(Class<?> dataClass) {
        return new ApiResponse() {

            @Override
            public Class<? extends Annotation> annotationType() {
                return ApiResponse.class;
            }

            @Override
            public boolean useReturnTypeSchema() {
                return false;
            }

            @Override
            public String responseCode() {
                return "default";
            }

            @Override
            public String ref() {
                return "";
            }

            @Override
            public Link[] links() {
                return new Link[] {};
            }

            @Override
            public Header[] headers() {
                return new Header[] {};
            }

            @Override
            public Extension[] extensions() {
                return new Extension[] {};
            }

            @Override
            public String description() {
                return "";
            }

            @Override
            public Content[] content() {
                return new Content[] { createContent(dataClass) };
            }
        };
    }

    private static Content createContent(Class<?> dataClass) {
        return new Content() {

            @Override
            public Class<? extends Annotation> annotationType() {
                return Content.class;
            }

            @Override
            public String mediaType() {
                return "";
            }

            @Override
            public ExampleObject[] examples() {
                return new ExampleObject[] {};
            }

            @Override
            public Schema schema() {
                return createSchema(dataClass);
            }

            @Override
            public SchemaProperty[] schemaProperties() {
                return new SchemaProperty[] {};
            }

            @Override
            public Schema additionalPropertiesSchema() {
                return createSchema(Void.class);
            }

            @Override
            public ArraySchema array() {
                return null;
            }

            @Override
            public Encoding[] encoding() {
                return new Encoding[] {};
            }

            @Override
            public Extension[] extensions() {
                return new Extension[] {};
            }

        };
    }

    private static Schema createSchema(Class<?> dataClass) {
        return new Schema() {

            @Override
            public Class<? extends Annotation> annotationType() {
                return Schema.class;
            }

            @Override
            public Class<?> implementation() {
                return dataClass;
            }

            @Override
            public Class<?> not() {
                return Void.class;
            }

            @Override
            public Class<?>[] oneOf() {
                return new Class<?>[] {};
            }

            @Override
            public Class<?>[] anyOf() {
                return new Class<?>[] {};
            }

            @Override
            public Class<?>[] allOf() {
                return new Class<?>[] {};
            }

            @Override
            public String name() {
                return "";
            }

            @Override
            public String title() {
                return "";
            }

            @Override
            public double multipleOf() {
                return 0;
            }

            @Override
            public String maximum() {
                return "";
            }

            @Override
            public boolean exclusiveMaximum() {
                return false;
            }

            @Override
            public String minimum() {
                return "";
            }

            @Override
            public boolean exclusiveMinimum() {
                return false;
            }

            @Override
            public int maxLength() {
                return Integer.MAX_VALUE;
            }

            @Override
            public int minLength() {
                return 0;
            }

            @Override
            public String pattern() {
                return "";
            }

            @Override
            public int maxProperties() {
                return 0;
            }

            @Override
            public int minProperties() {
                return 0;
            }

            @Override
            public String[] requiredProperties() {
                return new String[] {};
            }

            @Override
            public boolean required() {
                return false;
            }

            @Override
            public RequiredMode requiredMode() {
                return RequiredMode.AUTO;
            }

            @Override
            public String description() {
                return "";
            }

            @Override
            public String format() {
                return "";
            }

            @Override
            public String ref() {
                return "";
            }

            @Override
            public boolean nullable() {
                return false;
            }

            @Override
            public boolean readOnly() {
                return false;
            }

            @Override
            public boolean writeOnly() {
                return false;
            }

            @Override
            public AccessMode accessMode() {
                return AccessMode.AUTO;
            }

            @Override
            public String example() {
                return "";
            }

            @Override
            public ExternalDocumentation externalDocs() {
                return null;
            }

            @Override
            public boolean deprecated() {
                return false;
            }

            @Override
            public String type() {
                return "";
            }

            @Override
            public String[] allowableValues() {
                return new String[] {};
            }

            @Override
            public String defaultValue() {
                return "";
            }

            @Override
            public String discriminatorProperty() {
                return "";
            }

            @Override
            public DiscriminatorMapping[] discriminatorMapping() {
                return new DiscriminatorMapping[] {};
            }

            @Override
            public boolean hidden() {
                return false;
            }

            @Override
            public boolean enumAsRef() {
                return false;
            }

            @Override
            public Class<?>[] subTypes() {
                return new Class<?>[] {};
            }

            @Override
            public Extension[] extensions() {
                return new Extension[] {};
            }

            @Override
            public AdditionalPropertiesValue additionalProperties() {
                return AdditionalPropertiesValue.USE_ADDITIONAL_PROPERTIES_ANNOTATION;
            }

        };
    }
}
